import * as cc from "cc";
import VCTips from "../vc/VCTips";
import { ViewBase } from './../../../../framework/view/ViewBase';

const { ccclass, property, menu } = cc._decorator;
@ccclass("ViewTips")
@menu("GameView/ViewTips")
export default class ViewTips extends ViewBase{

    protected static prefabUrl:string = "game/prefab/mvc/common/Tips";
    public static className:string = "ViewTips"
    protected vc:VCTips = null;
    
    @property({ type: cc.UITransform,tooltip:"文本背景"})
    bg: cc.UITransform = null;
    @property({ type: cc.RichText,tooltip:"文本"})
    txt: cc.RichText = null;

    //生命周期：onInit(加载时只调一次)==>onOpen(每次showui时)==>onShow()==>onStart()==>onHide()==>onClose()
    /**只会在首次加载时调用一次，可以用于获取节点，绑定事件 */
    protected onInit() {
        super.onInit();
    }

    /**每次打开UI前，onStart前,每次呼出前赋值传参的时候用 */
    protected onOpen(){
        super.onOpen();
        this.txt.string = this.vc.str;
        this.scheduleOnce(()=>{
            let size = this.txt.getComponent(cc.UITransform).contentSize;
            this.bg.setContentSize(size.width + 20,size.height + 15);
        })
    }

    protected onStart(){
        this.vc.close();
    }
}